<template>
   <div class="adress-box">
    <CategoryHeadVue them="地址列表"></CategoryHeadVue>
    <main>
        <van-address-list
        v-model="chosenAddressId"
        :list="list"
        :disabled-list="disabledList"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
       />
    </main>
   </div>
</template>

<script>
import CategoryHeadVue from '@/components/Category-head.vue';
import axios from '@/Utils/server';
let userid = localStorage.getItem("userid")
export default {
    name:"useraderss-vue",
    components:{
        CategoryHeadVue
    },
    data() {
    return {
      chosenAddressId: '1',
      num:0,
      list: [],
      disabledList: [
      ],
    };
  },
  methods: {
    onAdd() {
      this.$router.push("/useraddaderss")
    },
    onEdit(item, index) {
      console.log('index: ', index);
      console.log('item: ', item);
      this.$router.push("/updateaderss?addressid="+item.id)
    },
  },
  created(){
    axios({
      url:"/api/address/list",
      params:{
      userid:userid
      }
    }).then(res=>{
      console.log(res.data.data);
      if(res.data.code==200){
      res.data.data.forEach(item => {
          let obj = {}
          obj.id = item.addressid;
          obj.name=item.name;
          obj.tel = item.tel;
          obj.address = item.province + item.city + item.county +item.addressDetail
          this.list.push(obj)
        });
      }
    })
  }
}
</script>

<style scoped>
.adress-box{
    display: flex;
    flex-direction: column;
    height: 100%;
}
main{
    flex: 1;
    overflow: auto;
}

</style>